
<%@ page import="org.codehaus.groovy.grails.commons.ConfigurationHolder; au.org.ala.phylojive.Tree" %>
<!doctype html>
<html>
	<head>
		<meta name="layout" content="main">
		<g:set var="entityName" value="${message(code: 'tree.label', default: 'Tree')}" />
		<title><g:message code="default.show.label" args="[entityName]" /></title>

        <script type="text/javascript">
            // <!--
            function exportCsv() {
                console.log("converting to CSV");
                var charJson = $("span[aria-labelledby='characters-label']").text();
                var separator = $(":input#separator").val();
                console.log("charJson", charJson);
                if (charJson) {
                    var url = "${createLink(controller: 'tree', action: 'convertCharJsonToCsv')}"; // ?csv=" + csv;
                    window.location.href = url + "?id=${treeInstance?.id}&separator=" + encodeURIComponent(separator);
                }

                return false;
            }
            // -->
        </script>
	</head>
	<body>
		<a href="#show-tree" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>
		<div class="nav" role="navigation">
			<ul>
				<li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
				<li><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></li>
				<li><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></li>
			</ul>
		</div>
		<div id="show-tree" class="content scaffold-show" role="main">
			<h1><g:message code="default.show.label" args="[entityName]" /></h1>
			<g:if test="${flash.message}">
			<div class="message" role="status">${flash.message}</div>
			</g:if>
			<ol class="property-list tree">
                <g:if test="${treeInstance?.name}">
				<li class="fieldcontain">
					<span id="name-label" class="property-label"><g:message code="tree.name.label" default="Name" /></span>
					
						<span class="property-value" aria-labelledby="name-label"><g:fieldValue bean="${treeInstance}" field="name"/></span>
					
				</li>
				</g:if>
			
				<g:if test="${treeInstance?.owner}">
				<li class="fieldcontain">
					<span id="owner-label" class="property-label"><g:message code="tree.owner.label" default="Owner" /></span>
					
						<span class="property-value" aria-labelledby="owner-label"><g:link controller="user" action="show" id="${treeInstance?.owner?.id}">${treeInstance?.owner?.encodeAsHTML()}</g:link></span>
					
				</li>
				</g:if>
			
				<g:if test="${treeInstance?.isPublic}">
				<li class="fieldcontain">
					<span id="isPublic-label" class="property-label"><g:message code="tree.isPublic.label" default="Is Public" /></span>
					
						<span class="property-value" aria-labelledby="isPublic-label"><g:formatBoolean boolean="${treeInstance?.isPublic}" /></span>
					
				</li>
				</g:if>

                <g:if test="${treeInstance?.isPublic}">
                    <li class="fieldcontain">
                        <span id="url-label" class="property-label"><g:message code="tree.publicUrl.label" default="Public URL" /></span>
                        <g:set var="url">${ConfigurationHolder.config.grails.serverURL}/treeViewer/show/${treeInstance.name}</g:set>
                        <span class="property-value" aria-labelledby="url-label"><a href="${url}">${url}</a></span>
                    </li>
                </g:if>
                <g:else>
                    <li class="fieldcontain">
                        <span id="url-label" class="property-label"><g:message code="tree.privateUrl.label" default="Private URL" /></span>
                        <g:set var="url">${ConfigurationHolder.config.grails.serverURL}/treeViewer/showPrivate/${treeInstance.privateUrlPath?:treeInstance.name}</g:set>
                        <span class="property-value" aria-labelledby="url-label"><a href="${url}">${url}</a>
                            <br/><br/><g:link class="button" action="generateNewPrivateUrlPath" id="${treeInstance.id}">Generate new private URL</g:link>
                        </span>

                    </li>
                </g:else>

                <g:if test="${treeInstance?.characters}">
                    <li class="fieldcontain">
                        <span id="button-convert-csv" class="property-label">Export characters as CSV</span>
                        <span class="property-value" aria-labelledby="button-convert-csv">
                            <button id="convertCsvToJson" onclick="exportCsv()">Download</button>
                            &nbsp;&nbsp;optional internal separator: <input type="text" id="separator" value="||" size="5" style="width: 30px;font-size: 14px;"/>
                        </span>
                    </li>
                </g:if>

				<g:if test="${treeInstance?.newick}">
				<li class="fieldcontain">
					<span id="newick-label" class="property-label"><g:message code="tree.newick.label" default="Newick" /></span>
					
						<span class="property-value" aria-labelledby="newick-label"><g:fieldValue bean="${treeInstance}" field="newick"/></span>
					
				</li>
				</g:if>
			
				<g:if test="${treeInstance?.characters}">
				<li class="fieldcontain">
					<span id="characters-label" class="property-label"><g:message code="tree.characters.label" default="Characters" /></span>
					
						<span class="property-value" aria-labelledby="characters-label"><g:fieldValue bean="${treeInstance}" field="characters"/></span>
					
				</li>
				</g:if>
			
				<g:if test="${treeInstance?.presentClade}">
				<li class="fieldcontain">
					<span id="presentClade-label" class="property-label"><g:message code="tree.presentClade.label" default="Present Clade" /></span>
					
						<span class="property-value" aria-labelledby="presentClade-label"><g:link controller="template" action="show" id="${treeInstance?.presentClade?.id}">${treeInstance?.presentClade?.encodeAsHTML()}</g:link></span>
					
				</li>
				</g:if>
			
				<g:if test="${treeInstance?.attribution}">
				<li class="fieldcontain">
					<span id="attribution-label" class="property-label"><g:message code="tree.attribution.label" default="Attribution" /></span>
					
						<span class="property-value" aria-labelledby="attribution-label"><g:fieldValue bean="${treeInstance}" field="attribution"/></span>
					
				</li>
				</g:if>
			
				<g:if test="${treeInstance?.highlight}">
				<li class="fieldcontain">
					<span id="highlight-label" class="property-label"><g:message code="tree.highlight.label" default="Highlight" /></span>
					
						<span class="property-value" aria-labelledby="highlight-label"><g:fieldValue bean="${treeInstance}" field="highlight"/></span>
					
				</li>
				</g:if>
			
				<g:if test="${treeInstance?.identifyLifeDataset}">
				<li class="fieldcontain">
					<span id="identifyLifeDataset-label" class="property-label"><g:message code="tree.identifyLifeDataset.label" default="Identify Life Dataset" /></span>
					
						<span class="property-value" aria-labelledby="identifyLifeDataset-label"><g:fieldValue bean="${treeInstance}" field="identifyLifeDataset"/></span>
					
				</li>
				</g:if>
			
			</ol>
			<g:form>
				<fieldset class="buttons">
					<g:hiddenField name="id" value="${treeInstance?.id}" />
					<g:link class="edit" action="edit" id="${treeInstance?.id}"><g:message code="default.button.edit.label" default="Edit" /></g:link>
					<g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />
				</fieldset>
			</g:form>
		</div>
	</body>
</html>
